Skip to main content

macOS http

macOS needs you to request a specific entitlement in order to access the network. To do that open macos/Runner/DebugProfile.entitlements and add the following key-value pair.

<key>com.apple.security.network.client</key>
<true/>

ios plist

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
import 'package:http/http.dart' as http;
import 'dart:convert';


Center(
// ignore: deprecated_member_use
child: RaisedButton(
child: Text('test'),
onPressed: () async {
String url = 'https://apis.juhe.cn/simpleWeather/query';
var res = await http.get(Uri.parse(url));
String body = res.body;
var json = jsonDecode(body);
print(json);
},
),
)